package com.ruoyi.platform.system.user.controller;

import com.ruoyi.base.annotaion.PermissionCheck;
import com.ruoyi.base.controller.BaseController;
import com.ruoyi.base.pojo.HttpResult;
import com.ruoyi.base.utils.arrays.ArrayUtils;
import com.ruoyi.base.utils.inputcheck.InputCheckUtils;
import com.ruoyi.platform.system.menu.enums.MenuEnum;
import com.ruoyi.platform.system.user.pojo.UserPlatQuery;
import com.ruoyi.platform.system.user.service.RegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户注册
 *
 * @author lcf
 * @version 0.0.1
 * @since 2020-11-13 05:40:22
 */
@Api(tags = {"用户注册"})
@RestController
@Scope("request")
@RequestMapping("/register")
public class RegisterController extends BaseController {
    @Autowired
    private RegisterService registerService;

    /**
     * 后台新增用户
     */
    @ApiOperation("后台新增用户")
    @PostMapping("/plat")
    @PermissionCheck(MenuEnum.USER_MANAGEMENT_ADD)
    public HttpResult<String> register(UserPlatQuery query, @ApiParam("角色code列表") Long[] roleCodeList) {
        InputCheckUtils.checkStr(query.getAccount(), "请输入账号");
        InputCheckUtils.checkStr(query.getNickName(), "请输入姓名");
        InputCheckUtils.checkArray(roleCodeList, "请选择角色");

        registerService.register(query, ArrayUtils.arrays2List(roleCodeList));
        return success();
    }
}